home *** CD-ROM | disk | FTP | other *** search
/ Champak 62 / Volume 62 - JOGO DISK .iso / Games / penguin_dinner.swf / scripts / __Packages / com / potapenko / managers / Conv.as
Text File  |  2008-03-17  |  17KB  |  583 lines

  1. class com.potapenko.managers.Conv extends Object
  2. {
  3.    var __conveyorON = true;
  4.    var __interval = 0;
  5.    var __bookmarks = 0;
  6.    var __shorts = 0;
  7.    var __turbo = false;
  8.    var __noSound = false;
  9.    var length = 0;
  10.    var isEmpty = true;
  11.    static var easingFunc = mx.transitions.easing.Strong.easeInOut;
  12.    static var __init = false;
  13.    static var gid = 0;
  14.    var id = 0;
  15.    var notTimeMode = false;
  16.    function Conv(notFrames)
  17.    {
  18.       super();
  19.       this.id = com.potapenko.managers.Conv.gid++;
  20.       this.__aConveyor = new Array();
  21.       com.potapenko.managers.Conv.checkForReloading();
  22.       if(!com.potapenko.managers.Conv.__init)
  23.       {
  24.          com.potapenko.managers.Conv.__init = true;
  25.          mx.transitions.OnEnterFrameBeacon.init();
  26.       }
  27.       if(!notFrames)
  28.       {
  29.          this.__frameTimer = new Object();
  30.          this.__frameTimer.root = this;
  31.          this.__frameTimer.sleep = true;
  32.          this.__frameTimer.onEnterFrame = function()
  33.          {
  34.             this.nTime = this.nTime + 1;
  35.             if(!this.sleep && this.nTime >= this.timeOut)
  36.             {
  37.                this.root.engine();
  38.                this.nTime = 0;
  39.             }
  40.          };
  41.       }
  42.    }
  43.    static function getInstance()
  44.    {
  45.       com.potapenko.managers.Conv.checkForReloading();
  46.       if(!com.potapenko.managers.Conv.__instance)
  47.       {
  48.          com.potapenko.managers.Conv.__instance = new com.potapenko.managers.Conv();
  49.       }
  50.       return com.potapenko.managers.Conv.__instance;
  51.    }
  52.    static function checkForReloading()
  53.    {
  54.       if(!_root.__OnEnterFrameBeacon)
  55.       {
  56.          com.potapenko.managers.Conv.__init = false;
  57.          if(com.potapenko.managers.Conv.__instance)
  58.          {
  59.             com.potapenko.managers.Conv.__instance.close();
  60.             delete com.potapenko.managers.Conv.__instance;
  61.          }
  62.       }
  63.    }
  64.    function play()
  65.    {
  66.       if(this.__conveyorON)
  67.       {
  68.          return undefined;
  69.       }
  70.       this.__conveyorON = true;
  71.    }
  72.    function stop()
  73.    {
  74.       this.__conveyorON = false;
  75.    }
  76.    function pause(p)
  77.    {
  78.       this.__aConveyor = [[this.empty,p,new com.potapenko.managers.conveyor.ConvReturn()]].concat(this.__aConveyor);
  79.    }
  80.    function addPause(p)
  81.    {
  82.       this.put(this.empty,p);
  83.    }
  84.    function clear()
  85.    {
  86.       this.__aConveyor = new Array();
  87.       this.__bookmarks = 0;
  88.       this.__shorts = 0;
  89.    }
  90.    function put()
  91.    {
  92.       var _loc3_ = new com.potapenko.managers.conveyor.ConvReturn();
  93.       if(this.__noSound && arguments[1] == "newSound")
  94.       {
  95.          return _loc3_;
  96.       }
  97.       arguments.push(_loc3_);
  98.       this.__aConveyor.push(arguments);
  99.       this.length = this.length + 1;
  100.       if(!this.__bookmarks && this.__aConveyor.length > 200 + this.__shorts)
  101.       {
  102.          var _loc4_ = this.__aConveyor.splice(100 + this.__shorts);
  103.          this.__shorts = this.__shorts + 1;
  104.          this.put(this,"__removeShort",0,_loc4_);
  105.       }
  106.       if(this.isEmpty)
  107.       {
  108.          this.wakeup();
  109.       }
  110.       return _loc3_;
  111.    }
  112.    function include()
  113.    {
  114.       this.put(this,"__addBookmark",0);
  115.       var _loc3_ = this.put.apply(this,arguments);
  116.       this.put(this,"__removeBookmark",0);
  117.       return _loc3_;
  118.    }
  119.    function anim(mc_anim, mc_to, params_ob)
  120.    {
  121.       var _loc7_ = params_ob.to_end;
  122.       var _loc21_ = params_ob.speed;
  123.       var _loc23_ = params_ob.notSwap;
  124.       var _loc13_ = params_ob.scale;
  125.       var _loc26_ = mc_to._x;
  126.       var _loc28_ = mc_to._y;
  127.       var _loc22_ = params_ob.delta;
  128.       var _loc5_ = params_ob.easing;
  129.       var _loc17_ = params_ob.frame || "1";
  130.       var _loc20_ = params_ob.duration;
  131.       var _loc24_ = params_ob.sound;
  132.       mc_to = this.validatePointScope(mc_anim,mc_to);
  133.       _loc22_ = this.validatePointScope(mc_anim,_loc22_);
  134.       if(!_loc21_)
  135.       {
  136.          _loc21_ = 20;
  137.       }
  138.       if(!_loc5_)
  139.       {
  140.          _loc5_ = com.potapenko.managers.Conv.easingFunc;
  141.       }
  142.       var _loc29_ = mc_anim._x;
  143.       var _loc27_ = mc_anim._y;
  144.       var _loc10_ = undefined;
  145.       var _loc9_ = undefined;
  146.       var _loc11_ = undefined;
  147.       var _loc12_ = undefined;
  148.       var _loc16_ = undefined;
  149.       var _loc15_ = undefined;
  150.       var _loc18_ = undefined;
  151.       var _loc19_ = undefined;
  152.       if(_loc13_)
  153.       {
  154.          _loc16_ = mc_anim._xscale;
  155.          _loc15_ = mc_anim._yscale;
  156.          _loc18_ = mc_to._xscale - _loc16_;
  157.          _loc19_ = mc_to._yscale - _loc15_;
  158.       }
  159.       var _loc25_ = undefined;
  160.       _loc25_ = Math.sqrt(Math.pow(Math.abs(mc_anim._x - mc_to._x),2) + Math.pow(Math.abs(mc_anim._y - mc_to._y),2));
  161.       var _loc6_ = this.__calculatePath(mc_anim,mc_to,_loc22_,_loc21_,_loc5_,_loc20_);
  162.       var _loc3_ = _loc6_.length;
  163.       if(_loc20_)
  164.       {
  165.          if(typeof _loc20_ == "string")
  166.          {
  167.             _loc3_ = _loc20_;
  168.          }
  169.          else
  170.          {
  171.             _loc17_ = _loc20_ / _loc3_;
  172.          }
  173.       }
  174.       if(isNaN(_loc3_))
  175.       {
  176.          return null;
  177.       }
  178.       if(!_loc23_)
  179.       {
  180.          this.put(this.__newDepth,mc_anim,0);
  181.       }
  182.       if(_loc24_)
  183.       {
  184.          this.put(new com.potapenko.util.MovieClipUtil(mc_anim),"newSound",0,"movie",50);
  185.       }
  186.       var _loc2_ = 1;
  187.       while(_loc2_ <= _loc3_)
  188.       {
  189.          if(!_loc7_ && _loc2_ >= _loc3_ - _loc3_ / 5)
  190.          {
  191.             break;
  192.          }
  193.          if(this.__turbo)
  194.          {
  195.             _loc2_ = !_loc7_ ? _loc3_ - _loc3_ / 5 : _loc3_;
  196.          }
  197.          if(_loc13_)
  198.          {
  199.             _loc11_ = _loc5_(_loc2_,_loc16_,_loc18_,_loc3_);
  200.             _loc12_ = _loc5_(_loc2_,_loc15_,_loc19_,_loc3_);
  201.             this.put(this.__scaleTo,0,mc_anim,_loc11_,_loc12_);
  202.          }
  203.          _loc10_ = _loc6_[_loc2_ - 1]._x;
  204.          _loc9_ = _loc6_[_loc2_ - 1]._y;
  205.          this.put(this.__moveTo,_loc17_,mc_anim,_loc10_,_loc9_);
  206.          _loc2_ = _loc2_ + 1;
  207.       }
  208.       if(!_loc23_)
  209.       {
  210.          this.put(this.__restoreDepth,mc_anim,0);
  211.       }
  212.       this.put(mc_anim,"_x",0,mc_to._x);
  213.       this.put(mc_anim,"_y",0,mc_to._y);
  214.       if(_loc13_)
  215.       {
  216.          this.put(mc_anim,"_xscale",0,mc_to._xscale);
  217.          this.put(mc_anim,"_yscale",0,mc_to._yscale);
  218.       }
  219.       return _loc6_;
  220.    }
  221.    function reverse()
  222.    {
  223.       this.__aConveyor.reverse();
  224.    }
  225.    function turbo_On()
  226.    {
  227.       this.__turbo = true;
  228.    }
  229.    function turbo_Off()
  230.    {
  231.       this.__turbo = false;
  232.    }
  233.    static function create(notFrames)
  234.    {
  235.       return new com.potapenko.managers.Conv(notFrames);
  236.    }
  237.    static function setTimeout()
  238.    {
  239.       var _loc3_ = 1;
  240.       var _loc4_ = arguments[_loc3_];
  241.       var _loc2_ = com.potapenko.managers.Conv.create();
  242.       if(isNaN(_loc4_))
  243.       {
  244.          _loc3_ = 2;
  245.          _loc4_ = arguments[_loc3_];
  246.       }
  247.       arguments[_loc3_] = 0;
  248.       _loc2_.addPause(_loc4_);
  249.       _loc2_.put.apply(_loc2_,arguments);
  250.       _loc2_.put(_loc2_,"close",0);
  251.    }
  252.    function close()
  253.    {
  254.       stop();
  255.       this.clear();
  256.       _global.MovieClip.removeListener(this.__frameTimer);
  257.       clearInterval(this.__interval);
  258.    }
  259.    function engine()
  260.    {
  261.       if(!this.__conveyorON)
  262.       {
  263.          this.pause("1");
  264.       }
  265.       clearInterval(this.__interval);
  266.       var cTime;
  267.       var tA = this.__aConveyor[0];
  268.       if(this.__aConveyor.length == 0)
  269.       {
  270.          this.sleep();
  271.          return undefined;
  272.       }
  273.       this.__aConveyor.shift();
  274.       this.length--;
  275.       var calledFunction;
  276.       var calledObject;
  277.       var argumentsObject;
  278.       var convReturn = tA.pop();
  279.       if(typeof tA[0] != "function")
  280.       {
  281.          calledObject = tA[0];
  282.          if(typeof calledObject == "string")
  283.          {
  284.             calledObject = eval(calledObject);
  285.          }
  286.          cTime = tA[2];
  287.          calledFunction = calledObject[tA[1]];
  288.          argumentsObject = tA.slice(3);
  289.          if(typeof calledFunction == "function")
  290.          {
  291.             convReturn.setReturnValue(calledFunction.apply(calledObject,this.validateArgs(argumentsObject)));
  292.          }
  293.          else
  294.          {
  295.             calledObject[tA[1]] = argumentsObject[0];
  296.          }
  297.       }
  298.       else if(!isNaN(tA[1]))
  299.       {
  300.          cTime = tA[1];
  301.          calledFunction = tA[0];
  302.          argumentsObject = tA.slice(2);
  303.          convReturn.setReturnValue(calledFunction.apply(null,this.validateArgs(argumentsObject)));
  304.       }
  305.       else if(!isNaN(tA[2]))
  306.       {
  307.          cTime = tA[2];
  308.          calledFunction = tA[0];
  309.          calledObject = tA[1];
  310.          if(typeof calledObject == "string")
  311.          {
  312.             calledObject = eval(calledObject);
  313.          }
  314.          argumentsObject = tA.slice(3);
  315.          convReturn.setReturnValue(calledFunction.apply(calledObject,this.validateArgs(argumentsObject)));
  316.       }
  317.       else
  318.       {
  319.          trace("com.potapenko.managers.Conv: engine: time format error");
  320.       }
  321.       if(cTime != 0 && !this.notTimeMode)
  322.       {
  323.          var timeType = typeof cTime;
  324.          var timeValue = Number(cTime);
  325.          if(timeType == "string")
  326.          {
  327.             if(this.__turbo)
  328.             {
  329.                timeValue = 1;
  330.             }
  331.             this.__frameTimer.timeOut = timeValue;
  332.             this.__frameTimer.nTime = 0;
  333.             this.__frameTimer.sleep = false;
  334.             this.__frame = true;
  335.          }
  336.          else if(timeType == "number")
  337.          {
  338.             this.__interval = setInterval(this,"engine",timeValue);
  339.             this.__frameTimer.sleep = true;
  340.             this.__frame = false;
  341.          }
  342.          else
  343.          {
  344.             this.engine();
  345.          }
  346.       }
  347.       else
  348.       {
  349.          this.engine();
  350.       }
  351.    }
  352.    function validateArgs(args)
  353.    {
  354.       var _loc1_ = 0;
  355.       while(_loc1_ < args.length)
  356.       {
  357.          var _loc2_ = args[_loc1_];
  358.          if(_loc2_ instanceof com.potapenko.managers.conveyor.ConvReturn)
  359.          {
  360.             args[_loc1_] = _loc2_.getReturnValue();
  361.          }
  362.          _loc1_ = _loc1_ + 1;
  363.       }
  364.       return args;
  365.    }
  366.    function sleep()
  367.    {
  368.       this.isEmpty = true;
  369.       if(this.__frameTimer)
  370.       {
  371.          _global.MovieClip.removeListener(this.__frameTimer);
  372.       }
  373.    }
  374.    function wakeup(isFrames)
  375.    {
  376.       this.isEmpty = false;
  377.       if(this.__frameTimer)
  378.       {
  379.          _global.MovieClip.addListener(this.__frameTimer);
  380.       }
  381.       this.engine();
  382.    }
  383.    function __removeShort()
  384.    {
  385.       this.__aConveyor = arguments[0].concat(this.__aConveyor);
  386.       this.__shorts = this.__shorts - 1;
  387.    }
  388.    function __addBookmark()
  389.    {
  390.       this.__aConveyor.push("#__bookmarks#");
  391.       this.__bookmarks = this.__bookmarks + 1;
  392.    }
  393.    function __removeBookmark(rev)
  394.    {
  395.       if(this.__bookmarks <= 0)
  396.       {
  397.          return undefined;
  398.       }
  399.       this.__bookmarks = this.__bookmarks - 1;
  400.       var _loc3_ = this.__aConveyor.length;
  401.       var _loc2_ = [];
  402.       while(this.__aConveyor[this.__aConveyor.length - 1] != "#__bookmarks#" && _loc3_-- > 0)
  403.       {
  404.          _loc2_.push(this.__aConveyor.pop());
  405.       }
  406.       this.__aConveyor.pop();
  407.       if(!rev)
  408.       {
  409.          _loc2_.reverse();
  410.       }
  411.       this.__aConveyor = _loc2_.concat(this.__aConveyor);
  412.    }
  413.    function __newDepth()
  414.    {
  415.       var _loc2_ = this;
  416.       _loc2_.____conv_anim_depth____ = _loc2_.getDepth();
  417.       var _loc3_ = _loc2_._parent.getNextHighestDepth();
  418.       if(!_loc3_ || _loc3_ < 0)
  419.       {
  420.          _loc3_ = 12123;
  421.       }
  422.       _loc2_.swapDepths(_loc3_);
  423.    }
  424.    function __restoreDepth()
  425.    {
  426.       var _loc2_ = this;
  427.       _loc2_.swapDepths(_loc2_.____conv_anim_depth____);
  428.       delete _loc2_.____conv_anim_depth____;
  429.    }
  430.    function __moveTo(mc, x, y)
  431.    {
  432.       mc._x = Math.round(x);
  433.       mc._y = Math.round(y);
  434.    }
  435.    function __scaleTo(mc, xs, ys)
  436.    {
  437.       mc._xscale = Math.round(xs);
  438.       mc._yscale = Math.round(ys);
  439.    }
  440.    function __calculatePath(start, to_point, delta, speed, func, duration)
  441.    {
  442.       var _loc21_ = [];
  443.       if(delta)
  444.       {
  445.          var _loc13_ = mx.transitions.easing.Regular.easeInOut;
  446.          var _loc12_ = mx.transitions.easing.Regular.easeInOut;
  447.          var _loc14_ = mx.transitions.easing.Regular.easeInOut;
  448.          var _loc27_ = {};
  449.          var _loc2_ = start;
  450.          var _loc7_ = to_point;
  451.          var _loc23_ = delta;
  452.          var _loc3_ = {};
  453.          _loc27_._x = (_loc2_._x + _loc7_._x) / 2;
  454.          _loc27_._y = (_loc2_._y + _loc7_._y) / 2;
  455.          _loc3_._x = _loc23_._x + (_loc23_._x - _loc27_._x);
  456.          _loc3_._y = _loc23_._y + (_loc23_._y - _loc27_._y);
  457.          var _loc4_ = [];
  458.          var _loc8_ = [];
  459.          var _loc35_ = this.__lengthCalculator(_loc2_,_loc7_);
  460.          var _loc32_ = this.__lengthCalculator(_loc2_,_loc23_);
  461.          var _loc31_ = this.__lengthCalculator(_loc23_,_loc7_);
  462.          var _loc30_ = _loc32_ + _loc31_;
  463.          var _loc9_ = undefined;
  464.          if(duration && typeof duration == "string")
  465.          {
  466.             _loc9_ = Number(duration);
  467.          }
  468.          else
  469.          {
  470.             _loc9_ = Math.round(_loc30_ / speed);
  471.          }
  472.          if(_loc9_ < 5 && !duration)
  473.          {
  474.             _loc9_ = 5;
  475.          }
  476.          if(duration)
  477.          {
  478.             _loc9_ = parseInt(duration);
  479.          }
  480.          if(_loc9_ < 5)
  481.          {
  482.             _loc9_ = 5;
  483.          }
  484.          var _loc10_ = Math.round(_loc9_ / 2);
  485.          var _loc11_ = _loc9_ - _loc10_;
  486.          var _loc16_ = undefined;
  487.          var _loc15_ = undefined;
  488.          var _loc5_ = undefined;
  489.          var _loc6_ = 1;
  490.          while(_loc6_ <= _loc9_)
  491.          {
  492.             _loc16_ = _loc14_(_loc6_,_loc2_._x,_loc7_._x - _loc2_._x,_loc9_);
  493.             _loc15_ = _loc14_(_loc6_,_loc2_._y,_loc7_._y - _loc2_._y,_loc9_);
  494.             _loc5_ = {_x:_loc16_,_y:_loc15_};
  495.             _loc4_.push(_loc5_);
  496.             _loc6_ = _loc6_ + 1;
  497.          }
  498.          _loc6_ = 1;
  499.          while(_loc6_ <= _loc10_)
  500.          {
  501.             _loc16_ = _loc13_(_loc6_,_loc2_._x,_loc3_._x - _loc2_._x,_loc10_);
  502.             _loc15_ = _loc13_(_loc6_,_loc2_._y,_loc3_._y - _loc2_._y,_loc10_);
  503.             _loc5_ = {_x:_loc16_,_y:_loc15_};
  504.             _loc8_.push(_loc5_);
  505.             _loc6_ = _loc6_ + 1;
  506.          }
  507.          _loc6_ = 1;
  508.          while(_loc6_ <= _loc11_)
  509.          {
  510.             _loc16_ = _loc12_(_loc6_,_loc3_._x,_loc7_._x - _loc3_._x,_loc11_);
  511.             _loc15_ = _loc12_(_loc6_,_loc3_._y,_loc7_._y - _loc3_._y,_loc11_);
  512.             _loc5_ = {_x:_loc16_,_y:_loc15_};
  513.             _loc8_.push(_loc5_);
  514.             _loc6_ = _loc6_ + 1;
  515.          }
  516.          _loc6_ = 0;
  517.          while(_loc6_ < _loc4_.length)
  518.          {
  519.             _loc4_[_loc6_]._x = (_loc4_[_loc6_]._x + _loc8_[_loc6_]._x) / 2;
  520.             _loc4_[_loc6_]._y = (_loc4_[_loc6_]._y + _loc8_[_loc6_]._y) / 2;
  521.             _loc6_ = _loc6_ + 1;
  522.          }
  523.          _loc21_ = _loc4_;
  524.       }
  525.       else
  526.       {
  527.          _loc30_ = this.__lengthCalculator(start,to_point);
  528.          if(duration && typeof duration == "string")
  529.          {
  530.             _loc9_ = Number(duration);
  531.          }
  532.          else
  533.          {
  534.             _loc9_ = Math.round(_loc30_ / speed);
  535.          }
  536.          if(_loc9_ < 5 && !duration)
  537.          {
  538.             _loc9_ = 5;
  539.          }
  540.          var _loc25_ = to_point._x - start._x;
  541.          var _loc24_ = to_point._y - start._y;
  542.          var _loc22_ = start._x;
  543.          var _loc26_ = start._y;
  544.          _loc6_ = 1;
  545.          while(_loc6_ <= _loc9_)
  546.          {
  547.             _loc16_ = func(_loc6_,_loc22_,_loc25_,_loc9_);
  548.             _loc15_ = func(_loc6_,_loc26_,_loc24_,_loc9_);
  549.             _loc21_.push({_x:_loc16_,_y:_loc15_});
  550.             _loc6_ = _loc6_ + 1;
  551.          }
  552.       }
  553.       return _loc21_;
  554.    }
  555.    function __lengthCalculator(a, b)
  556.    {
  557.       return Math.sqrt(Math.pow(Math.abs(a._x - b._x),2) + Math.pow(Math.abs(a._y - b._y),2));
  558.    }
  559.    function validatePointScope(animatedPoint, point)
  560.    {
  561.       if(point == null || typeof point != "movieclip")
  562.       {
  563.          return point;
  564.       }
  565.       var _loc2_ = {x:point._x,y:point._y};
  566.       point._parent.localToGlobal(_loc2_);
  567.       animatedPoint._parent.globalToLocal(_loc2_);
  568.       var _loc3_ = {_x:_loc2_.x,_y:_loc2_.y,_xscale:point._xscale,_yscale:point._yscale,_width:point._width,_height:point._height};
  569.       return _loc3_;
  570.    }
  571.    function isNotTimeMode()
  572.    {
  573.       return this.notTimeMode;
  574.    }
  575.    function setNotTimeMode(notTimeMode)
  576.    {
  577.       this.notTimeMode = notTimeMode;
  578.    }
  579.    function empty()
  580.    {
  581.    }
  582. }
  583.